package com.test.deencredit.analytics_deencredit.bean_deencredit

import com.google.gson.Gson
import com.test.deencredit.analytics_deencredit.util_deencredit.AnalyticsUtil_deencredit
import com.test.deencredit.config_deencredit.Constant_deencredit
import com.test.deencredit.util_deencredit.AESCryptUtil_deencredit
import com.test.deencredit.util_deencredit.UserInfoUtil_deencredit
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.RequestBody
import okhttp3.RequestBody.Companion.toRequestBody

open class PamBase_deencredit(
    /** product */
    var product: String = "",
    /** clientType */
    var clientType: String = "",
    /** aduidPath */
    var aduidPath: String = "",
    var path: String = "",
    /** token */
    var token: String = "",
    /** userId */
    var userId: String = "",
    /** 是否限制广告id，1是 0否 */
    var isLimitAdTrackingEnabled: String = "",
    /** 接口版本号 */
    var apiVersion: String = "v3",
    /** aduid */
    var aduid: String = "",
    /** androidId */
    var androidId: String = "",
    /** advertId */
    var advertId: String = "",
    /** version */
    var version: String = ""
) {
    init {
        this.advertId = AnalyticsUtil_deencredit.getAdId_deencredit()
        this.aduidPath = AnalyticsUtil_deencredit.getAndroidId_deencredit()
        this.token = UserInfoUtil_deencredit.getInstance_deencredit().token_deencredit
        this.product = Constant_deencredit.PRODUCT_deencredit
        this.clientType = "ANDROID"
        this.isLimitAdTrackingEnabled = AnalyticsUtil_deencredit.getAdEnabled_deencredit().toString()
        this.aduid = AnalyticsUtil_deencredit.getAdId_deencredit()
        this.userId = UserInfoUtil_deencredit.getInstance_deencredit().userId_deencredit
        this.version = Constant_deencredit.APP_VERSION_deencredit
        this.androidId = AnalyticsUtil_deencredit.getAndroidId_deencredit()
    }

    open fun toEncryptParams(path1: String): String {
        val path2 = path1.replace("/".toRegex(), "")
        path = path2
        val content = Gson().toJson(this).trim()
        return AESCryptUtil_deencredit.encryptDefault_deencredit(content)
    }

    open fun toRequestBody(path: String): RequestBody {
        val encrypted: String = toEncryptParams(path)
        val mediaType = "text/plain".toMediaTypeOrNull()
        return encrypted.toRequestBody(mediaType)
    }
}